package top.huhuiyu.springboot2.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.huhuiyu.springboot2.dao.TbNewsMapper;
import top.huhuiyu.springboot2.entity.BaseResult;
import top.huhuiyu.springboot2.entity.NewsQuery;
import top.huhuiyu.springboot2.entity.TbNews;

import java.util.List;


@RestController
public class IndexController {

    @Autowired
    private TbNewsMapper tbNewsMapper;

    @RequestMapping("")
    public String index() {
        return "欢迎使用黑暗骑士的网站";
    }

    @RequestMapping("/entity")
    public BaseResult entity(String message) {
        BaseResult result = new BaseResult();
        if (StringUtils.hasText(message)) {
            result.setCode(200);
            result.setMessage(message);
            result.setSuccess(true);
        } else {
            result.setCode(500);
            result.setMessage("没有传入消息");
            result.setSuccess(false);
        }
        return result;
    }

    // http://127.0.0.1:10100/queryAll
    @RequestMapping("/queryAll")
    public List<TbNews> queryAll() {
        return tbNewsMapper.queryAll(new NewsQuery());
    }

}
